//
//  WDTestViewController.m
//  winterTest
//
//  Created by wd on 15/11/12.
//  Copyright © 2015年 Wei Chuang Le ,Ltd. All rights reserved.
//

#import "WDTestViewController.h"

@interface WDTestViewController () <UITableViewDelegate, UITableViewDataSource>
/** tableview */
@property (nonatomic, weak) UITableView *tableView;
@end

@implementation WDTestViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.title = @"test";
    
    if (TestShowVC_Type_Modal == self.showVC_Type) {
        UIBarButtonItem *barBtn1=[[UIBarButtonItem alloc]initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(cancleButtonClicked)];
        self.navigationItem.leftBarButtonItem=barBtn1;
    }
    
    UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:tableView];
    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    self.tableView = tableView;
    
    // 刷新
    ODRefreshControl *refreshControl = [[ODRefreshControl alloc]initInScrollView:self.tableView];
    [refreshControl addTarget:self action:@selector(dropViewDidBeginRefresh:) forControlEvents:UIControlEventValueChanged];
}


- (void)cancleButtonClicked
{
    if (self.cancleActionBlock) {
        self.cancleActionBlock(YES);
    }
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)dropViewDidBeginRefresh:(ODRefreshControl *)refreshControl
{
    NSLog(@"refresh end");
    
    double delayInSeconds = 2.0;
    dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
    dispatch_after(delayTime, dispatch_get_main_queue(), ^(void){
        // code to be executed on the main queue after delay
        [refreshControl endRefreshing];
    });
}

- (void)dropViewDidLoad:(SVInfiniteScrollingView *)infiniteControl
{
    NSLog(@"infiniteControl end");
    
    double delayInSeconds = 2.0;
    dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
    dispatch_after(delayTime, dispatch_get_main_queue(), ^(void){
        // code to be executed on the main queue after delay
        [infiniteControl stopAnimating];
        //        self.tableView.showsInfiniteScrolling = YES;
    });
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 9;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    cell.textLabel.text = [NSString stringWithFormat:@"cell - %ld",indexPath.row];
    return cell;
}


@end
